package com.sgb.kjwl.view.ui.adapter.pick;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.pick.PickExpertListEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;


public class PickExpertAdapter extends BaseRecycleAdapter<PickExpertListEntity> {

    private TextView tvTime;
    private TextView tvEdit;
    private TextView tvDelete;
    private IChildClick iChildClick;

    public PickExpertAdapter(Context context, List<PickExpertListEntity> datas) {
        super(context, R.layout.item_pick_expert, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final PickExpertListEntity entity) {
        holder.setBinding(BR.viewModel, entity);

        tvTime = holder.itemView.findViewById(R.id.tv_time);
        tvEdit = holder.itemView.findViewById(R.id.tv_edit);
        tvDelete = holder.itemView.findViewById(R.id.tv_delete);
        if (TextUtils.isEmpty(entity.getCreated())) {
            tvTime.setVisibility(View.GONE);
        } else {
            tvTime.setText("添加时间：" + entity.getCreated());
        }

        tvEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                iChildClick.onEdit(entity);
            }
        });
        tvDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                iChildClick.onDelete(entity,holder.getLayoutPosition());
            }
        });

    }

    public interface IChildClick {
        void onEdit(PickExpertListEntity pickExpertListEntity);

        void onDelete(PickExpertListEntity pickExpertListEntity,int position);
    }

    public void onIChildClick(IChildClick iChildClick) {
        this.iChildClick = iChildClick;
    }
}
